﻿$(document).ready(function () {

    layui.use('table', function () {
        var table = layui.table,
            form = layui.form;
        table.render({
            elem: '#test'
            , url: '/Recode/Display'
            , cellMinWidth: 80
            , cols: [[
                { field: 'TaskTiltle', width: 125, title: '任务标题' }
                , { field: 'Publisher', width: 80, title: '发布人' }
                , { field: 'oneer', width: 80, title: '执行人' }
                , { field: 'CompletionTime', width: 160, title: '发布时间', sort: true, templet: "<div>{{Format(d.CompletionTime,'yyyy-MM-dd hh:mm:ss')}}</div>" }
                , { field: 'ReleaseTime', title: '执行时间', width: 160, sort: true, templet: "<div>{{Format(d.ReleaseTime,'yyyy-MM-dd hh:mm:ss')}}</div>" }
                , { field: 'TaskContent', title: '任务内容', width: 350 }
                , { field: 'Statuse', title: '是否完成', width: 120, templet: '#switchTpl', unresize: true }
                , { fixed: 'right', title: '操作', width: 65, align: 'center', toolbar: '#barDemo' }
            ]]
            , page: true
            , id: 'testReload'
        });

        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event == 'del') {
                //删除
                layer.confirm('真的要删除吗?', function (index) {
                    $.ajax({
                        url: "/Recode/Delete?ID=" + data.Id,
                        type: "Post",
                        success: function (data) {
                            if (data.success) {
                                layer.msg(data.msg, {
                                    title: '提示框',
                                    icon: 1,
                                    time: 2000
                                }, function () {
                                    location.reload();//刷新当前页面
                                });
                            }
                            else {
                                layer.msg(data.msg, {
                                    title: '提示框',
                                    icon: 1,
                                    time: 2000
                                });
                            }
                        }
                    });
                });
            }
        });

        //监听启用和禁用操作
        form.on('switch(sexDemo)', function (obj) {
            var tip = "启用";
            var id = this.id;
            var tap = true;
            //layer.tips(this.id + ' ' + this.value + '：' + obj.elem , obj.othis);
            if (this.value === "0") {
                tip = "保存";
                tap = 1;
                //启用的功能代码
                $.ajax({
                    url: "/Recode/Update?id=" + id + "&status=" + tap,
                    type: "Post",
                    success: function (result) {
                        if (result.success) {
                            layer.msg(tip + '成功！', {
                                title: '提示框',
                                icon: 1,
                                time: 2000
                            }, function () {
                                location.reload();//刷新当前页面
                            });
                        }
                        else {
                            layer.msg(tip + '失败！', {
                                title: '提示框',
                                icon: 2,
                                time: 2000
                            });
                        }
                    }
                });
            }
        });


    });

    $("#sele").click(function () {
        TableReload();
    });

    function TableReload() {
        var table = layui.table;
        //获取页面管理员名称和时间
        var oneer = $("#oneer").val();
        var TaskTiltle = $("#TaskTiltle").val();
        var CompletionTime = $("#demo").val();
        //上述方法等价于
        table.reload('testReload', {
            where: { //设定异步数据接口的额外参数，任意设
                oneer: oneer,
                TaskTiltle: TaskTiltle,
                CompletionTime: CompletionTime
                //…
            }
        });
    };



});